/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package newkfp;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author labib.farag
 */
@Stateless
public class LogFacade extends AbstractFacade<Log> implements Serializable {

    @PersistenceContext(unitName = "KFPNEWPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public LogFacade() {
        super(Log.class);
    }

    public List<Log> getLogAtPeriod(Date from, Date to) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String ffrom = sdf.format(from);
            String fto = sdf.format(to);
            Date fFromDate = new SimpleDateFormat("yyyy-MM-dd").parse(ffrom);
            Date fToDate = new SimpleDateFormat("yyyy-MM-dd").parse(fto);
            Query query = getEntityManager().createNamedQuery("Log.findByActionDatePariod");
            query.setParameter("createDateFrom",fFromDate);
            query.setParameter("createDateTo", fToDate);
            List list = query.getResultList();
            return list;
        } catch (ParseException ex) {
            return new ArrayList<Log>();
        }
    }
}
